const goodController = require('../../controller/goodController')


const defaultConfig = {
  isTokenChecker: false,
  isValidate: false
}
module.exports = {
  get: {
    '/getGoods': Object.assign(defaultConfig, {
      func: async (req, res, next) => {
        const goods = await goodController.getGoods()
        res.json({
          status: 200,
          msg: '获取商品成功',
          data: {
            goods
          }
        })
      }
    })
  },
  post: {
    '/upsert': Object.assign(defaultConfig, {
      isTokenChecker: true,
      func: async (req, res, next) => {
        const { good } = req.good
        const result = await goodController.upsertGood(good)
        res.json({ status: 200, msg: '保存商品成功', data: {} })
      }
    }),
    '/delete': Object.assign(defaultConfig, {
      isTokenChecker: true,
      func: async (req, res, next) => {
        const { goods } = req.goods
        const result = await goodController.delete(goods)
        res.json({ status: 200, msg: '删除商品成功', data: {} })
      }
    })
  }
}
